package cn.daichi.elasticsearchdemo.controller;

import cn.daichi.elasticsearchdemo.service.SearchService;
import cn.daichi.elasticsearchdemo.vo.PostVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SearchController {

    private final SearchService searchService;

    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }


    @ResponseBody
    @GetMapping("search")
    public List<PostVo> search(String keyword) {
        Page page = new Page();
        page.setSize(10000);
        page.setCurrent(1);

        IPage iPage = searchService.search(page, keyword);
        return iPage.getRecords();

    }

}
